package com.wendu.oa.api.security;

import com.wendu.oa.common.Result;
import com.wendu.oa.dto.MenuDto;
import com.wendu.oa.dto.RoleDto;
import com.wendu.oa.service.security.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/security/role")
public class RoleController {

    @Autowired
    private RoleService roleService;

    @PutMapping("/funs/{ro_id}")
    public Result assignFuns(@PathVariable Integer ro_id, @RequestBody Integer[] f_ids){
        roleService.setFuns(ro_id,f_ids);
        return Result.OK();
    }

    @GetMapping("/funs")
    public Result allFuns(){
        List<MenuDto> funList =  roleService.getFunList();
        return Result.OK(funList);
    }


    @GetMapping("")
    public Result roleList(RoleDto roleDto){
        return Result.OK(roleService.getRolePage(roleDto));
    }

    @GetMapping("/funs/{ro_id}")
    public Result roleFunIds(@PathVariable Integer ro_id){
        Integer[] funIds = roleService.getRoleFunIds(ro_id);
        return Result.OK(funIds);
    }


}
